

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>纠删码 &mdash; Ceph Documentation</title>
  

  
  <link rel="stylesheet" href="../../../_static/ceph.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/css/custom.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../../_static/favicon.ico"/>
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/underscore.js"></script>
        <script src="../../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../genindex/" />
    <link rel="search" title="Search" href="../../../search/" />
    <link rel="next" title="纠删码配置" href="../erasure-code-profile/" />
    <link rel="prev" title="存储池" href="../pools/" /> 
</head>

<body class="wy-body-for-nav">

   
  <header class="top-bar">
    

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../../">Ceph 存储集群</a> &raquo;</li>
        
          <li><a href="../">集群运维</a> &raquo;</li>
        
      <li>纠删码</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../../_sources/rados/operations/erasure-code.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
  </header>
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search"  style="background: #eee" >
          

          
            <a href="../../../">
          

          
            
            <img src="../../../_static/logo.png" class="logo" alt="Logo"/>
          
          </a>

          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search/" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../../start/intro/">Ceph 简介</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../install/">安装 Ceph</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephadm/">Cephadm</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../../">Ceph 存储集群</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../../configuration/">配置</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../">运维</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="../operating/">操纵集群</a></li>
<li class="toctree-l3"><a class="reference internal" href="../health-checks/">健康检查</a></li>
<li class="toctree-l3"><a class="reference internal" href="../monitoring/">监控集群</a></li>
<li class="toctree-l3"><a class="reference internal" href="../monitoring-osd-pg/">监控 OSD 和归置组</a></li>
<li class="toctree-l3"><a class="reference internal" href="../user-management/">用户管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../pg-repair/">修复 PG 不一致状态</a></li>
<li class="toctree-l3"><a class="reference internal" href="../data-placement/">数据归置概览</a></li>
<li class="toctree-l3"><a class="reference internal" href="../pools/">存储池</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">纠删码</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id2">创建纠删码存储池样板</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id3">纠删码配置</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id4">在纠删码存储池上启用重写功能</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id6">纠删码存储池与缓存分级</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id9">纠删码存储池的恢复</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id10">术语</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id11">内容列表</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="../cache-tiering/">分级缓存</a></li>
<li class="toctree-l3"><a class="reference internal" href="../placement-groups/">归置组</a></li>
<li class="toctree-l3"><a class="reference internal" href="../balancer/">均衡器</a></li>
<li class="toctree-l3"><a class="reference internal" href="../upmap/">使用 pg-upmap</a></li>
<li class="toctree-l3"><a class="reference internal" href="../crush-map/">CRUSH 图</a></li>
<li class="toctree-l3"><a class="reference internal" href="../crush-map-edits/">手动编辑一个 CRUSH 图</a></li>
<li class="toctree-l3"><a class="reference internal" href="../stretch-mode/">Stretch Clusters</a></li>
<li class="toctree-l3"><a class="reference internal" href="../change-mon-elections/">Configure Monitor Election Strategies</a></li>
<li class="toctree-l3"><a class="reference internal" href="../add-or-rm-osds/">增加/删除 OSD</a></li>
<li class="toctree-l3"><a class="reference internal" href="../add-or-rm-mons/">增加/删除监视器</a></li>
<li class="toctree-l3"><a class="reference internal" href="../devices/">设备管理</a></li>
<li class="toctree-l3"><a class="reference internal" href="../bluestore-migration/">迁移到 BlueStore</a></li>
<li class="toctree-l3"><a class="reference internal" href="../control/">命令参考</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/community/">Ceph 社区</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-mon/">监视器故障排除</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-osd/">OSD 故障排除</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/troubleshooting-pg/">归置组排障</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/log-and-debug/">日志记录和调试</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/cpu-profiling/">CPU 剖析</a></li>
<li class="toctree-l3"><a class="reference internal" href="../../troubleshooting/memory-profiling/">内存剖析</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../../man/">    手册页</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../troubleshooting/">故障排除</a></li>
<li class="toctree-l2"><a class="reference internal" href="../../api/">APIs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../../cephfs/">Ceph 文件系统</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../rbd/">Ceph 块设备</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../radosgw/">Ceph 对象网关</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/">Ceph 管理器守护进程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mgr/dashboard/">Ceph 仪表盘</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api/">API 文档</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../architecture/">体系结构</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/developer_guide/">开发者指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../dev/internals/">Ceph 内幕</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../governance/">项目管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../foundation/">Ceph 基金会</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../ceph-volume/">ceph-volume</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/general/">Ceph 版本（总目录）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../releases/">Ceph 版本（索引）</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../security/">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../glossary/">Ceph 术语</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../jaegertracing/">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../translation_cn/">中文版翻译资源</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../">Ceph</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
<div id="dev-warning" class="admonition note">
  <p class="first admonition-title">Notice</p>
  <p class="last">This document is for a development version of Ceph.</p>
</div>
  <div id="docubetter" align="right" style="padding: 5px; font-weight: bold;">
    <a href="https://pad.ceph.com/p/Report_Documentation_Bugs">Report a Documentation Bug</a>
  </div>

  
  <div class="section" id="ecpool">
<span id="id1"></span><h1>纠删码<a class="headerlink" href="#ecpool" title="Permalink to this headline">¶</a></h1>
<p>A Ceph pool is associated to a type to sustain the loss of an OSD
(i.e. a disk since most of the time there is one OSD per disk). The
default choice when <a class="reference external" href="../pools">creating a pool</a> is <em>replicated</em>,
meaning every object is copied on multiple disks. The <a class="reference external" href="https://en.wikipedia.org/wiki/Erasure_code">Erasure Code</a> pool type can be used
instead to save space.</p>
<div class="section" id="id2">
<h2>创建纠删码存储池样板<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<p>The simplest erasure coded pool is equivalent to <a class="reference external" href="https://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_5">RAID5</a> and
requires at least three hosts:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ceph osd pool create ecpool erasure
pool &#39;ecpool&#39; created
$ echo ABCDEFGHI | rados --pool ecpool put NYAN -
$ rados --pool ecpool get NYAN -
ABCDEFGHI
</pre></div>
</div>
</div>
<div class="section" id="id3">
<h2>纠删码配置<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2>
<p>默认的纠删码配置可容忍两个 OSD 的损失，相当于副本数为三的多副本存储池，但只需 2TB 的空间即可存储 1TB 数据，而无需 3TB 。默认配置可这样查看：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ceph osd erasure-code-profile get default
k=2
m=2
plugin=jerasure
crush-failure-domain=host
technique=reed_sol_van
</pre></div>
</div>
<p>确定合理的配置文件很重要，因为存储池创建后就不能再修改了。
要改的话，只能另外创建一个采用新配置的存储池，
然后再把所有对象挪过去。</p>
<p>配置文件里最重要的参数是 <em>K</em> 、 <em>M</em> 和
<em>crush-failure-domain</em> ，因为它们决定了存储的开销和数据的持久性。
例如，假设期望的系统架构必须能承受两个故障机架和 67% 的开销，
可以用下列配置文件：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ceph osd erasure-code-profile set myprofile \
   k=3 \
   m=2 \
   crush-failure-domain=rack
$ ceph osd pool create ecpool erasure myprofile
$ echo ABCDEFGHI | rados --pool ecpool put NYAN -
$ rados --pool ecpool get NYAN -
ABCDEFGHI
</pre></div>
</div>
<p>对象 <em>NYAN</em> 将被分割成三块（ <em>K=3</em> ）、
并额外创建两个 <em>校验块</em>（ <em>M=2</em> ）。
<em>M</em> 值决定了在不丢数据的前提下可以同时失去多少 OSD 。
<em>crush-failure-domain=rack</em> 能使创建的 CRUSH 规则可确保两个<em>校验块</em>不会存储在同一机架上。</p>
<p>More information can be found in the <a class="reference external" href="../erasure-code-profile">erasure code profiles</a> documentation.</p>
</div>
<div class="section" id="id4">
<h2>在纠删码存储池上启用重写功能<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h2>
<p>默认情况下，纠删码存储池只适用于像 RGW 这样进行完整对象写入和追加的场景。</p>
<p>从 Luminous 起，在纠删码存储池里进行部分写入的功能可以在存储池配置里启用，这样 RBD 和 CephFS 就可以使用纠删码存储池存储数据了：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ceph</span> <span class="n">osd</span> <span class="n">pool</span> <span class="nb">set</span> <span class="n">ec_pool</span> <span class="n">allow_ec_overwrites</span> <span class="n">true</span>
</pre></div>
</div>
<p>只有当存储池座落于 bluestore 格式的 OSD 上时才能启用此功能，因为 bluestore 的校验和功能在深度洗刷时能探测到位翻转或者其它的损坏。除了不安全外，在 filestore 上使用 EC 重写的性能也比
bluestore 上差得多。</p>
<p>纠删码存储池不支持 omap ，所以用于 RBD 和 CephFS 时你必须让它们把数据存到 EC 存储池里、而元数据存到副本存储池里。对 RBD 而言，这意味着在创建映像时要用纠删码存储池作 <code class="docutils literal notranslate"><span class="pre">--data-pool</span></code> （数据存储池）的参数：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">rbd</span> <span class="n">create</span> <span class="o">--</span><span class="n">size</span> <span class="mi">1</span><span class="n">G</span> <span class="o">--</span><span class="n">data</span><span class="o">-</span><span class="n">pool</span> <span class="n">ec_pool</span> <span class="n">replicated_pool</span><span class="o">/</span><span class="n">image_name</span>
</pre></div>
</div>
<p>对 CephFS 而言，可在文件系统创建期间、或通过<a class="reference external" href="../../../cephfs/file-layouts">文件布局</a>把一个纠删码存储池设置为默认的数据存储池。</p>
</div>
<div class="section" id="id6">
<h2>纠删码存储池与缓存分级<a class="headerlink" href="#id6" title="Permalink to this headline">¶</a></h2>
<p>纠删码存储池与副本存储池相比需要的计算资源更多，而且还缺少一些功能，像 omap 。要消除这些局限性，可以在纠删码存储池前加一个<a class="reference external" href="../cache-tiering">缓存层</a>。</p>
<p>例如，假设存储池 <em>hot-storage</em> 性能比较好：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ ceph osd tier add ecpool hot-storage
$ ceph osd tier cache-mode hot-storage writeback
$ ceph osd tier set-overlay ecpool hot-storage
</pre></div>
</div>
<p>这样就把 <em>hot-storage</em> 存储池配置成了 <em>ecpool</em> 的缓存层，模式为
<em>writeback</em> 。如此一来，到 <em>ecpool</em> 的每个写和读实际上用的是
<em>hot-storage</em> ，而且还受益于其灵活性和速度。</p>
<p>更详细的文档请参阅<a class="reference external" href="../cache-tiering">分级缓存</a>。</p>
</div>
<div class="section" id="id9">
<h2>纠删码存储池的恢复<a class="headerlink" href="#id9" title="Permalink to this headline">¶</a></h2>
<p>If an erasure coded pool loses some shards, it must recover them from the others.
This generally involves reading from the remaining shards, reconstructing the data, and
writing it to the new peer.
In Octopus, erasure coded pools can recover as long as there are at least <em>K</em> shards
available. (With fewer than <em>K</em> shards, you have actually lost data!)</p>
<p>Prior to Octopus, erasure coded pools required at least <em>min_size</em> shards to be
available, even if <em>min_size</em> is greater than <em>K</em>. (We generally recommend min_size
be <em>K+2</em> or more to prevent loss of writes and data.)
This conservative decision was made out of an abundance of caution when designing the new pool
mode but also meant pools with lost OSDs but no data loss were unable to recover and go active
without manual intervention to change the <em>min_size</em>.</p>
</div>
<div class="section" id="id10">
<h2>术语<a class="headerlink" href="#id10" title="Permalink to this headline">¶</a></h2>
<dl class="simple">
<dt><em>chunk</em></dt><dd><p>when the encoding function is called, it returns chunks of the same
size. Data chunks which can be concatenated to reconstruct the original
object and coding chunks which can be used to rebuild a lost chunk.</p>
</dd>
<dt><em>K</em></dt><dd><p>the number of data <em>chunks</em>, i.e. the number of <em>chunks</em> in which the
original object is divided. For instance if <em>K</em> = 2 a 10KB object
will be divided into <em>K</em> objects of 5KB each.</p>
</dd>
<dt><em>M</em></dt><dd><p>the number of coding <em>chunks</em>, i.e. the number of additional <em>chunks</em>
computed by the encoding functions. If there are 2 coding <em>chunks</em>,
it means 2 OSDs can be out without losing data.</p>
</dd>
</dl>
</div>
<div class="section" id="id11">
<h2>内容列表<a class="headerlink" href="#id11" title="Permalink to this headline">¶</a></h2>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../erasure-code-profile/">纠删码配置</a></li>
<li class="toctree-l1"><a class="reference internal" href="../erasure-code-jerasure/">Jerasure 纠删码插件</a></li>
<li class="toctree-l1"><a class="reference internal" href="../erasure-code-isa/">ISA 纠删码插件</a></li>
<li class="toctree-l1"><a class="reference internal" href="../erasure-code-lrc/">局部自修复纠删码插件</a></li>
<li class="toctree-l1"><a class="reference internal" href="../erasure-code-shec/">SHEC 纠删码插件</a></li>
<li class="toctree-l1"><a class="reference internal" href="../erasure-code-clay/">CLAY 码插件</a></li>
</ul>
</div>
</div>
</div>



           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="../erasure-code-profile/" class="btn btn-neutral float-right" title="纠删码配置" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="../pools/" class="btn btn-neutral float-left" title="存储池" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2016, Ceph authors and contributors. Licensed under Creative Commons Attribution Share Alike 3.0 (CC-BY-SA-3.0).

    </p>
  </div> 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>